package com.eli.pingserver.entities

import cn.hutool.db.Entity
import java.io.Serializable

/**
 * 服务器存活信息
 */
class ServerSurviveInfo : Serializable{


    /** 主键ID  */
    var id: Int? = null

    /** 服务器名称  */
    var serverName: String? = null

    /** 服务器IP  */
    var serverIp: String? = null

    /** 状态 0正常 1异常  */
    var status: String? = null

    /** 更新时间  */
    var updatedTime: String? = null

    companion object{

        val updateStatusSql = "update server_survive_info set status = '%s',updated_time = '%s' where id = %s"

        /**
         * Entity转换成ServerSurviveInfo
         */
        fun entity2ServerSurviveInfo(it: Entity): ServerSurviveInfo{
            val serverSurviveInfo = ServerSurviveInfo()
            serverSurviveInfo.id = it.getInt("id")
            serverSurviveInfo.serverName = it.getStr("server_name")
            serverSurviveInfo.serverIp = it.getStr("server_ip")
            serverSurviveInfo.status = it.getStr("status")
            serverSurviveInfo.updatedTime = it.getStr("updated_time")
            return serverSurviveInfo
        }

        /**
         * 获取根棍状态的sql
         */
        fun getUpdateStatusSQL(it: ServerSurviveInfo): String {

            return String.format(updateStatusSql, it.status, it.updatedTime, it.id)
        }

    }
}